<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../docs-assets/ico/favicon.png">

    <title>Carousel Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="../dist/css/bootstrap.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="docs-assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->

  </head>
<!-- NAVBAR
================================================== -->
  <body>
  
    <div class="navbar-wrapper">
      <div class="container">

        <div class="navbar navbar-inverse navbar-static-top" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
             
            </div>
            <div class="navbar-collapse collapse">
              <ul class="nav navbar-nav">
                <li class="active"><a href="adminupmc.html">Accueil</a></li>
                <li><a href="#about"></a></li>
				<li><a href="manage.html">Gérer les incidents</a></li>
				<li><a href="#about"></a></li>
				<li class="dropdown">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown">Diffuser des infos <b class="caret"></b></a>
				    <ul class="dropdown-menu">
						<li><a href="diffuserinfos.html">Déposer une information</a></li>
						<li class="divider"></li>
						<li><a href="consulter-infos.html">Consulter les informations</a></li>
						<li class="divider"></li>
					</ul>
				</li>
                <li class="dropdown">
				  <li><a href="objetsperdustrouves.html">Objet perdus/trouvés</a></li>
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Compte <b class="caret"></b></a>
                  <ul class="dropdown-menu">
					<li class="dropdown-header"> <div id="user-info" hidden> Enregistré comme  <span id="us"> </span></div> </li>
						<li><a href="#" class="log-out">Déconnexion</a></li>
                    <li class="divider"></li>
                  </ul>
				</li>
              </ul>
            </div>
          </div>
        </div>

      </div>
    </div>

	<div id = "check-out" style = "display:block;text-align: center;border:solid;border-color:#B59775;background-color:#D7B997;margin-right:20%;margin-left:20%;margin-bottom: auto;margin-top: auto;padding:auto;">
		<!--<h1 style="text-color:black;text-align: center;font-weight:bold">Consulter les incidents</h1>-->
		<!--<div style="border-top:solid;border-color:#B59775;background-color:#D7B997;padding:auto;margin-left:auto;margin-right:auto;margin-bottom:auto;margin-top:auto;">
			<div style = "display:block-inline;margin:auto;">
				 <input type="checkbox" value="selected-id">
			</div>
			<div style="display:block-inline;margin:auto;">
			Hello world</br>Je suis ton père !!!!!!!
			</div>
		</div>-->
	</div>
	<div style = "display:block;text-align: center;border:solid;border-color:#B59775;background-color:#D7B997;margin-right:20%;margin-left:20%;margin-bottom: auto;margin-top: auto;padding:auto;">
		<h1 style="text-color:black;text-align: center;font-weight:bold">Supprimer un incident</h1>
		<div id = "delete" style="border-top:solid;border-color:#B59775;background-color:#D7B997;padding:auto;margin-left:auto;margin-right:auto;margin-bottom:auto;margin-top:auto;">
			Séléctionnez l'annonce à supprimer.(1 seule sélection)</br>
			<button id="btn-delete" class="btn btn-lg btn-primary btn-block" >Supprimer incident</button>
		</div>
	</div>
	<div style = "display:block;text-align: center;border:solid;border-color:#B59775;background-color:#D7B997;margin-right:20%;margin-left:20%;margin-bottom: auto;margin-top: auto;padding:auto;">
		<h1 style="text-color:black;text-align: center;font-weight:bold">Modifier le statut d'un incident</h1>
		Séléctionnez l'annonce à modifier puis cliquez sur modifier le statut:(1 seule sélection)
		<div id = "alter" style="border-top:solid;border-color:#B59775;background-color:#D7B997;padding:auto;margin-left:auto;margin-right:auto;margin-bottom:auto;margin-top:auto;">
			
			
		</div>
		<button id="btn-alter" class="btn btn-lg btn-primary btn-block"  >Modifier statut</button>
	</div>
	
	
      <!-- FOOTER -->
      <footer>
        <p class="pull-right"><a href="#">Back to top</a></p>
        <p>&copy; 2013 Company, Inc. &middot; <a href="#">Privacy</a> &middot; <a href="#">Terms</a></p>
		<div id="user-info" hidden>
        Enregistré comme  <span id="us"> </span>
		<a href="#" class="log-out">Déconnexion</a>
      </div>
      </footer>

    </div><!-- /.container -->
	
	

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
	<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    <script src="../js/underscore-1.1.6.js"></script>
    
	<script src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script>
    <script src="../dist/js/bootstrap.min.js"></script>
    <script src="../docs-assets/js/holder.js"></script>
	<script src="../js/logInInfo.js"></script>
	<script>
		$(function(){
			
			$("#btn-delete").click(function(){
				var id = -1;
				id = getValueSelected();
				if(id != -1){
					//Launch query for delete post
					//location.reload();
					console.log("valeur select "+id);
					var IncidentModel = Parse.Object.extend("IncidentModel");

					var query = new Parse.Query(IncidentModel);
					query.get(id, {
					 success: function(incident) {
						// The object was retrieved successfully.
						incident.destroy({
							success: function(myObject) {
								// The object was deleted from the Parse Cloud.
								console.log("Objet suppr");
							},
							error: function(myObject, error) {
								// The delete failed.
								// error is a Parse.Error with an error code and description.
								console.log("Objet non suppr");
							}
						});
					 },
					 error: function(object, error) {
						// The object was not retrieved successfully.
						// error is a Parse.Error with an error code and description.
					 }
					});
				}
				else{
					console.log("Aucune entrée séléctionné !");
				}
			});
			$("#btn-alter").click(function(){
				//Launch query for alter
				// Create the object.
				var id = -1;
				id = getValueSelected();
				if(id != -1){
					console.log("saisie recup:"+id);
					var IncidentModel = Parse.Object.extend("IncidentModel");
					var incident = new IncidentModel();
					incident.set("objectId",id);
					incident.save(null, {
					  success: function(obj) {
						// Now let's update it with some new data. In this case, only cheatMode and score
						// will get sent to the cloud. playerName hasn't changed.
						//incident.set("cheatMode", true);
						//incident.set("score", 1338);
						//incident.save();
						
						//obj.set("status", 1);
						//obj.save();
						//console.log("status à 1");
						incident.set("status", 1);
						incident.save();
						console.log("status à 1");
					  }
					});
					
					//location.reload();
				}
				else
					//console.log("Aucune saisie récupèré");
					console.log("Aucune saisie récupéré");
			});
			
			
			 function getValueSelected(){
				var entries = document.getElementsByTagName("input");
				var i=0;
				var idValue=-1;
				for(i=0;i<entries.length;i++){
					if(entries[i].checked == true){
						idValue=entries[i].value;
					}
				}
				if(idValue != -1){
					return idValue;
				}
				else{
					return -1;
				}
			 }
			 function createContainerAndInsert(containerId,type,data){
						
				//document.getElementsByTagName("head")[0].appendChild(holdercss);
				var new_element3 = document.createElement(type);
				new_element3.innerHTML = data;
				$(containerId).append(new_element3);
			 }
			 function getData(){				
				var IncidentModel = Parse.Object.extend("IncidentModel");
				var query = new Parse.Query(IncidentModel);
				//query.equalTo("playerName", "Dan Stemkoski");
				query.include(["signaledBy"]);
				query.find({
				  success: function(results) {
					//alert("Successfully retrieved " + results.length + " scores.");
					// Do something with the returned Parse.Object values
					var entete = '<h1 style="text-color:black;text-align: center;font-weight:bold">Liste des incidents</h1>';
					createContainerAndInsert("#check-out","h1",entete);
					for (var i = 0; i < results.length; i++) { 
					  var object = results[i];
					  var urltof = object.get('photo');
					  //alert(object.id + ' - ' + object.get('description'));
					  var data = '<div style="border-top:solid;border-color:#B59775;background-color:#D7B997;padding:auto;margin-left:auto;margin-right:auto;margin-bottom:auto;margin-top:auto;"><div style = "display:block-inline;margin:auto;"><input type="checkbox" value="'+object.id+'"></div><div style="display:block-inline;margin:auto;">'+
								'Crée le:'+object.createdAt+'</br>';
								if(urltof != null)
									data+='</br></br>'+'<img width="200" height="150" alt="photo_incident" src='+urltof.url()+'></img>'+'</br></br>';
								data+='Mise à jour le:'+object.updatedAt+'</br>'+
								'Signalé par:'+object.get("signaledBy").get("username")+'</br>'+
								'Type:'+object.get('type')+'</br>'+
								'Priorité:'+object.get('priority')+'</br>'+
								'Place:'+object.get('place')+'</br>'+
								'Problème résolut:'+object.get('status')+'</br>'+
								'Description:</br>'+object.get('description')+'</br>'+
								'</div></div>';
						createContainerAndInsert("#check-out",'div',data);
					}
				  },
				  error: function(error) {
					console.log("Error: " + error.code + " " + error.message);
				  }
				});
			 }
			 function loadData(){
				
				var entete = '<h1 style="text-color:black;text-align: center;font-weight:bold">Consulter les incidents</h1>';
				createContainerAndInsert("#check-out","h1",entete);
				var data = '<div style="border-top:solid;border-color:#B59775;background-color:#D7B997;padding:auto;margin-left:auto;margin-right:auto;margin-bottom:auto;margin-top:auto;"><div style = "display:block-inline;margin:auto;"><input type="checkbox" value="selected-id"></div><div style="display:block-inline;margin:auto;">Hello world</br>Je suis ton père !!!!!!!</div></div>';
				//createContainerAndInsert("#check-out",'div',data);
				//createContainerAndInsert("#check-out",'div',data);
				//createContainerAndInsert("#check-out",'div',data);
				//createContainerAndInsert("#check-out",'div',data);
			 }
			 
			// loadData();
			//Récupère et affiche les données en BDD
			 getData();
			 
		});
	</script>

  </body>
</html>
<!--
<div class="input-group">
						<li><input type="text" class="form-control" placeholder="Username" /></li>
						<li><input type="password" class="form-control" placeholder="Password" /></li>
					</div>
                    <li><button>Se connecter</button></li> 
					<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
-->
